package com.ruoyi.web.controller.consume;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.consume.domain.BladeConsumeTemporary;
import com.ruoyi.consume.domain.SimpleConsume;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.consume.domain.GraftinglabelConsumeTemporary;
import com.ruoyi.consume.service.IGraftinglabelConsumeTemporaryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 查看临时领用信息Controller
 *
 * @author ruoyi
 * @date 2021-07-27
 */
@Api("查看临时领用信息")
@RestController
@RequestMapping("/consume/graftinglabeltemcon")
public class GraftinglabelConsumeTemporaryController extends BaseController
{
    @Autowired
    private IGraftinglabelConsumeTemporaryService graftinglabelConsumeTemporaryService;

    /**
     * 查询查看临时领用信息列表
     */
    @ApiOperation("查询查看临时领用信息列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:graftinglabeltemcon:list')")
    @GetMapping("/list")
    public TableDataInfo list(GraftinglabelConsumeTemporary graftinglabelConsumeTemporary)
    {
        startPage();
        List<GraftinglabelConsumeTemporary> list = graftinglabelConsumeTemporaryService.selectGraftinglabelConsumeTemporaryList(graftinglabelConsumeTemporary);
        return getDataTable(list);
    }

    /**
     * 导出查看临时领用信息列表
     */
    @ApiOperation("导出查看临时领用信息列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:graftinglabeltemcon:export')")
    @Log(title = "查看临时领用信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GraftinglabelConsumeTemporary graftinglabelConsumeTemporary)
    {
        List<GraftinglabelConsumeTemporary> list = graftinglabelConsumeTemporaryService.selectGraftinglabelConsumeTemporaryList(graftinglabelConsumeTemporary);
        ExcelUtil<GraftinglabelConsumeTemporary> util = new ExcelUtil<GraftinglabelConsumeTemporary>(GraftinglabelConsumeTemporary.class);
        return util.exportExcel(list, "查看临时领用信息数据");
    }

    /**
     * 获取查看临时领用信息详细信息
     */
    @ApiOperation("获取查看临时领用信息详细信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:graftinglabeltemcon:query')")
    @GetMapping(value = "/{graftinglabelConsumeTemporaryId}")
    public AjaxResult getInfo(@PathVariable("graftinglabelConsumeTemporaryId") Long graftinglabelConsumeTemporaryId)
    {
        return AjaxResult.success(graftinglabelConsumeTemporaryService.selectGraftinglabelConsumeTemporaryById(graftinglabelConsumeTemporaryId));
    }

    /**
     * 新增查看临时领用信息
     */
    @ApiOperation("新增查看临时领用信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:graftinglabeltemcon:add')")
    @Log(title = "查看临时领用信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GraftinglabelConsumeTemporary graftinglabelConsumeTemporary)
    {
        return toAjax(graftinglabelConsumeTemporaryService.insertGraftinglabelConsumeTemporary(graftinglabelConsumeTemporary));
    }

    /**
     * 修改查看临时领用信息
     */
    @ApiOperation("修改查看临时领用信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:graftinglabeltemcon:edit')")
    @Log(title = "查看临时领用信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GraftinglabelConsumeTemporary graftinglabelConsumeTemporary)
    {
        return toAjax(graftinglabelConsumeTemporaryService.updateGraftinglabelConsumeTemporary(graftinglabelConsumeTemporary));
    }

    /**
     * 删除查看临时领用信息
     */
    @ApiOperation("删除查看临时领用信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:graftinglabeltemcon:remove')")
    @Log(title = "查看临时领用信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{graftinglabelConsumeTemporaryIds}")
    public AjaxResult remove(@PathVariable Long[] graftinglabelConsumeTemporaryIds)
    {
        return toAjax(graftinglabelConsumeTemporaryService.deleteGraftinglabelConsumeTemporaryByIds(graftinglabelConsumeTemporaryIds));
    }

    /**
     * 获取用户列表下拉框
     */
    @ApiOperation("获取用户列表下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:graftinglabeltemcon:username')")
    @GetMapping("/username")
    public TableDataInfo getUserName(){

        List<GraftinglabelConsumeTemporary> list = graftinglabelConsumeTemporaryService.getUserName();
        List<SimpleConsume> simpleConsumes = new ArrayList<>();
        for (GraftinglabelConsumeTemporary graftinglabelConsumeTemporary:list) {
            Long id = graftinglabelConsumeTemporary.getUserId();
            String name = graftinglabelConsumeTemporary.getUserName();
            SimpleConsume consume = new SimpleConsume(id,name);
            simpleConsumes.add(consume);
        }
        return getDataTable(simpleConsumes);
    }
}
